﻿
namespace Jayden.Dll.Core.Persistence.Queries
{
	public class QueryField : QueryFilterBinaryOperand
	{
		private string m_TableName;
		private string m_FieldName;
		private string m_AliasName;

		public QueryField(string tableName, string fieldName, string aliasName = null)
		{
			m_TableName = tableName;
			m_FieldName = fieldName;
			m_AliasName = aliasName;
		}

		public string TableName { get { return m_TableName; } set { m_TableName = value; } }
		public string FieldName { get { return m_FieldName; } set { m_FieldName = value; } }
		public string AliasName { get { return m_AliasName; } set { m_AliasName = value; } }
		public string FullName { get { return m_TableName == null ? m_FieldName : string.Format("{0}.{1}", m_TableName, m_FieldName);}}
		public string QueryName { get { return m_AliasName != null ? m_AliasName : FullName; } }

		public override string ToString()
		{
			string fullName = FullName;
			if(m_AliasName != null)
				return string.Format("{0} AS {1}", fullName, m_AliasName);
			return fullName;
		}
	}
}
